home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / termsorc.lha / Extras / Source / gtlayout-source.lha / LT_Rebuild.c < prev    next >
C/C++ Source or Header  |  1995-09-24  |  6KB  |  284 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8.  
  9. BOOL LIBENT
  10. LT_RebuildTagList(REG(a0) LayoutHandle *handle,REG(d0) BOOL clear,REG(a1) struct TagItem *TagParams)
  11. {
  12.     struct TagItem    *item,
  13.             *list;
  14.     struct IBox    *bounds = NULL;
  15.     WORD         RightEdge,
  16.              BottomEdge;
  17.  
  18.     list = TagParams;
  19.  
  20.     while(item = NextTagItem(&list))
  21.     {
  22.         switch(item -> ti_Tag)
  23.         {
  24.             case LAWN_Bounds:
  25.  
  26.                 bounds = (struct IBox *)item -> ti_Data;
  27.                 break;
  28.         }
  29.     }
  30.  
  31.     if(handle)
  32.     {
  33.         struct Gadget    *gadget,
  34.                 *next;
  35.         ObjectNode    *node;
  36.         LONG         left,top;
  37.         struct IBox     newBounds;
  38.         LONG         i;
  39.         struct Image    **ImagePtr;
  40.  
  41.         if(!handle -> SizeVerified)
  42.         {
  43.             RemoveGList(handle -> Window,handle -> List,(UWORD)-1);
  44. #ifdef DO_BOOPSI_KIND
  45.             if(handle -> BOOPSIList)
  46.                 RemoveGList(handle -> Window,(struct Gadget *)handle -> BOOPSIList,(UWORD)-1);
  47. #endif    /* DO_BOOPSI_KIND */
  48.         }
  49.         gadget = handle -> List;
  50.  
  51.         while(gadget)
  52.         {
  53.             if(GETOBJECT(gadget,node))
  54.             {
  55.                 LTP_PutStorage(node);
  56.  
  57.                 ImagePtr = NULL;
  58.  
  59.                 switch(node -> Type)
  60.                 {
  61. #ifdef DO_GAUGE_KIND
  62.                     case GAUGE_KIND:
  63.  
  64.                         node -> Special . Gauge . LastPercentage = -1;
  65.                         break;
  66. #endif    /* DO_GAUGE_KIND */
  67.  
  68.                     case BUTTON_KIND:
  69.  
  70.                         ImagePtr = &node -> Special . Button . ButtonImage;
  71.                         break;
  72.  
  73.                     case PICKER_KIND:
  74.  
  75.                         ImagePtr = &node -> Special . Picker . Image;
  76.                         break;
  77.  
  78.                     case TAPEDECK_KIND:
  79.  
  80.                         ImagePtr = &node -> Special . TapeDeck . ButtonImage;
  81.                         break;
  82.  
  83.                     case INCREMENTER_KIND:
  84.  
  85.                         ImagePtr = &node -> Special . Incrementer . Image;
  86.                         break;
  87.  
  88.                     case STRING_KIND:
  89.  
  90.                         if(!node -> Special . String . Backup)
  91.                             node -> Special . String . Backup = (STRPTR)LTP_Alloc(handle,node -> Special . String . MaxChars + 1);
  92.  
  93.                         if(node -> Special . String . Backup)
  94.                         {
  95.                             strcpy(node -> Special . String . Backup,((struct StringInfo *)gadget -> SpecialInfo) -> Buffer);
  96.  
  97.                             node -> Special . String . String = node -> Special . String . Backup;
  98.                         }
  99.  
  100.                         node -> Special . String . Picker = NULL;
  101.  
  102.                         break;
  103.  
  104.                     case TEXT_KIND:
  105.  
  106.                         node -> Special . Text . Picker = NULL;
  107.                         break;
  108.  
  109.                     case INTEGER_KIND:
  110.  
  111.                         node -> Special . Integer . LeftIncrementer    = NULL;
  112.                         node -> Special . Integer . RightIncrementer    = NULL;
  113.  
  114.                         break;
  115. #ifdef DO_LEVEL_KIND
  116.                     case LEVEL_KIND:
  117.  
  118.                         ImagePtr = &node -> Special . Level . LevelImage;
  119.                         break;
  120. #endif    /* DO_LEVEL_KIND */
  121.                 }
  122.  
  123.                 if(ImagePtr && *ImagePtr)
  124.                 {
  125.                     DisposeObject(*ImagePtr);
  126.  
  127.                     *ImagePtr = NULL;
  128.                 }
  129.  
  130.                 node -> Host = NULL;
  131.             }
  132.  
  133.             gadget = gadget -> NextGadget;
  134.         }
  135.  
  136.         FreeGadgets(handle -> List);
  137.  
  138.         handle -> List = NULL;
  139.  
  140. #ifdef DO_BOOPSI_KIND
  141.         gadget = (struct Gadget *)handle -> BOOPSIList;
  142.  
  143.         while(gadget)
  144.         {
  145.             next = gadget -> NextGadget;
  146.  
  147.             if(GETOBJECT(gadget,node))
  148.             {
  149.                 DisposeObject(gadget);
  150.  
  151.                 if(node -> Type == BOOPSI_KIND)
  152.                 {
  153.                     if(node -> Special . BOOPSI . ClassBase)
  154.                     {
  155.                         CloseLibrary(node -> Special . BOOPSI . ClassBase);
  156.  
  157.                         node -> Special . BOOPSI . ClassBase = NULL;
  158.                     }
  159.                 }
  160.  
  161.                 node -> Host = NULL;
  162.             }
  163.  
  164.             gadget = next;
  165.         }
  166.  
  167.         handle -> BOOPSIList = NULL;
  168.         handle -> BOOPSIPrevious = NULL;
  169. #endif    /* DO_BOOPSI_KIND */
  170.  
  171.         LTP_Free(handle,handle -> GadgetArray,sizeof(struct Gadget *) * handle -> Count);
  172.  
  173.         handle -> GadgetArray = NULL;
  174.  
  175.         handle -> Count = handle -> Index = 0;
  176.  
  177.         LTP_ResetGroups(handle -> TopGroup);
  178.  
  179.         if(!bounds)
  180.         {
  181. //            LTP_GetDisplayClip(handle -> Screen,&newBounds . Left,&newBounds . Top,&newBounds . Width,&newBounds . Height);
  182.  
  183.             bounds = &newBounds;
  184.  
  185.             newBounds . Left    = 0;
  186.             newBounds . Top        = 0;
  187.             newBounds . Width    = handle -> Window -> Width;
  188.             newBounds . Height    = handle -> Window -> Height;
  189.         }
  190.  
  191.         left        = handle -> Window -> BorderLeft;
  192.         top        = handle -> Window -> BorderTop;
  193.         RightEdge    = handle -> Window -> BorderRight;
  194.         BottomEdge    = handle -> Window -> BorderBottom;
  195.  
  196.         if(!handle -> FlushLeft)
  197.         {
  198.             left        += handle -> InterWidth;
  199.             RightEdge    += handle -> InterWidth;
  200.         }
  201.  
  202.         if(!handle -> FlushTop)
  203.         {
  204.             top        += handle -> InterHeight;
  205.             BottomEdge    += handle -> InterHeight;
  206.         }
  207.  
  208.         LTP_CreateGadgets(handle,bounds,left,top,left + RightEdge,top + BottomEdge);
  209.  
  210.         if(handle -> Failed)
  211.         {
  212.             handle -> SizeVerified = FALSE;
  213.  
  214.             EraseRect(&handle -> RPort,handle -> Window -> BorderLeft,handle -> Window -> BorderTop,handle -> Window -> Width - (handle -> Window -> BorderRight + 1),handle -> Window -> Height - (handle -> Window -> BorderBottom + 1));
  215.  
  216.             RefreshWindowFrame(handle -> Window);
  217.  
  218.             return(FALSE);
  219.         }
  220.  
  221.         if(clear)
  222.         {
  223.             EraseRect(&handle -> RPort,handle -> Window -> BorderLeft,handle -> Window -> BorderTop,handle -> Window -> Width - (handle -> Window -> BorderRight + 1),handle -> Window -> Height - (handle -> Window -> BorderBottom + 1));
  224.  
  225.             if(!handle -> SizeVerified)
  226.                 RefreshWindowFrame(handle -> Window);
  227.         }
  228.  
  229.         handle -> SizeVerified = FALSE;
  230.  
  231.         LTP_AddGadgets(handle);
  232.  
  233.         handle -> Previous = NULL;
  234.  
  235.         for(i = 0 ; i < handle -> Count ; i++)
  236.         {
  237.             if(handle -> GadgetArray[i])
  238.             {
  239.                 if(GETOBJECT(handle -> GadgetArray[i],node))
  240.                 {
  241.                     if(LIKE_STRING_KIND(node) || (node -> Type == INTEGER_KIND))
  242.                     {
  243.                         if(!handle -> Previous)
  244.                             handle -> Previous = handle -> GadgetArray[i];
  245.                     }
  246.                 }
  247.             }
  248.         }
  249.  
  250.         return(TRUE);
  251.     }
  252.     else
  253.         return(FALSE);
  254. }
  255.  
  256.  
  257. /*****************************************************************************/
  258.  
  259.  
  260. BOOL __stdargs
  261. LT_RebuildTags(LayoutHandle *Handle,BOOL Clear,...)
  262. {
  263.     va_list VarArgs;
  264.     BOOL    Result;
  265.  
  266.     va_start(VarArgs,Clear);
  267.     Result = LT_RebuildTagList(Handle,Clear,(struct TagItem *)VarArgs);
  268.     va_end(VarArgs);
  269.  
  270.     return(Result);
  271. }
  272.  
  273.  
  274. /*****************************************************************************/
  275.  
  276.  
  277. BOOL LIBENT
  278. LT_Rebuild(REG(a0) LayoutHandle *handle,REG(a1) struct IBox *bounds,REG(a2) LONG extraWidth,REG(d0) LONG extraHeight,REG(d1) BOOL clear)
  279. {
  280.     return(LT_RebuildTags(handle,clear,
  281.         LAWN_Bounds,bounds,
  282.     TAG_DONE));
  283. }
  284.